#include "triangulationprogessdialog.h"
#include "ui_triangulationprogessdialog.h"

TriangulationProgessDialog::TriangulationProgessDialog(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::TriangulationProgessDialog)
{
    m_ui->setupUi(this);
    this->installEventFilter(this);
}

TriangulationProgessDialog::~TriangulationProgessDialog()
{
    delete m_ui;
}

void TriangulationProgessDialog::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void TriangulationProgessDialog::setCompletenessStatus(float percentage, int imagesCompleted, int totalImages)
{
    m_ui->progressBar->setValue((int)(percentage*10));
    if(imagesCompleted<totalImages)
        m_ui->label_2->setText(QString("Images rendered: ")+QString("").setNum(imagesCompleted) + QString("/")+QString("").setNum(totalImages));
    else
        m_ui->label_2->setText("Retrieving triangulation...");
}

void TriangulationProgessDialog::cancelButtonPressed()
{
    emit processCanceled();
}

bool TriangulationProgessDialog::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::KeyPress)
    {
        //   QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
        return true;
    }
    else
    {
        // standard event processing
        return QObject::eventFilter(obj, event);
    }
}
